﻿//弹出窗口,内容可自定义，标题为“提示”
function PopContent(data) {
    var temp = "<div id='PopId'><div>&nbsp;</div><div>" + data + "</div></div>";
    return temp;
}

function PopWindow(data) {
    PopWindow(data, false);
}
function PopWindow(data, modalorNot) {
    $(PopContent(data)).dialog({
        title: "提示！",
        width: '250px',
        modal: modalorNot,
        buttons: {
            "确定": function () {
                $(this).dialog("close");
            }
        }
    });
}

function PopWindow(data, modalorNot, callback) {
    $(PopContent(data)).dialog({
        title: "提示！",
        width: '250px',
        modal: modalorNot,
        buttons: {
            "确定": function () {
                $(this).dialog("close");
                if (callback != null)
                    callback();

            }
        }
    });
}


var selectLoad = function (id, url, value, callBack) {
    $.getJSON(appRoot + url + '?rd=' + rdTime(), function (data, textStatus) {
        $("#" + id).empty();
        $.each(data, function (i, itemvalue) {
            $("#" + id).append($("<option></option>").val(itemvalue.Value).html(itemvalue.Text));
        });
        if (value != null)
            $("#" + id).val(value);
        if (callBack != null)
            callBack();
    });
};

var selectChangeLoad = function (id, parentId, url, value) {
    $("#" + parentId).change(function () {
        /*$.getJSON(appRoot + url + $("#" + parentId).val(), function (data, textStatus) {
        $("#" + id).empty();
        $.each(data, function (i, itemvalue) {
        $("#" + id).append($("<option></option>").val(itemvalue.Value).html(itemvalue.Text));
        });
        if (value != null)
        $("#" + id).val(value);
        });*/
        selectLoad(id, url + $("#" + parentId).val());
    });
};

var selectChangeLoadDef = function (parentId, id1, url1, id2, url2) {
    $("#" + parentId).change(function () {
        if ($("#" + parentId).val() == 0) {
            selectLoad(id1, url1 + 0);
            if (id2 != null && url2 != null)
                selectLoad(id2, url2 + 0);
        }
    });
};

var allCheckEvent = function (id, subName) {
    $("#" + id).click(
        function () {
            if (this.checked) {
                $("input[name='" + subName + "']").each(function () { this.checked = true; });
            } else {
                $("input[name='" + subName + "']").each(function () { this.checked = false; });
            }
        });
};

var getCheckStr = function (subName, splitStr) {
    var re = "";
    $("input[name='" + subName + "']").each(function () { if (this.checked) { re += this.value + splitStr; } });
    return re;
};

var bindTextAreaEditor = function (id, random, at) {
    var upload = appRoot + 'Aspx/upload.aspx?rd=' + random;
    if (at != null && at != "")
        upload = upload + "&at=" + at;
    $('#' + id).xheditor({ tools: 'Cut,Copy,Paste,Pastetext,|,Blocktag,Fontface,FontSize,Bold, Italic,Underline,Strikethrough,FontColor,BackColor,SelectAll,Removeformat,|,Align,List,Outdent,Indent,|,Link,Unlink,Img,Flash,Media,Hr,Table,|,Source,Preview,Fullscreen', skin: 'o2007blue', upLinkUrl: upload, upImgUrl: upload, upFlashUrl: upload, upMediaUrl: upload, upLinkExt: 'txt,rar,zip,pdf,doc,docx,ppt,pptx' });
};

var bindTextAreaImgEditor = function (id, random, at) {
    var upload = appRoot + 'Aspx/upload.aspx?rd=' + random;
    if (at != null && at != "")
        upload = upload + "&at=" + at;
    $('#' + id).xheditor({ tools: 'FontSize,Bold,Italic,Underline,Strikethrough,|,Align,List,|,Link,Img,Source', skin: 'o2007blue', upLinkUrl: upload, upImgUrl: upload, upFlashUrl: upload, upMediaUrl: upload, upLinkExt: 'txt,rar,zip,pdf,doc,docx,ppt,pptx' });
};

var bindTextOnlyAreaEditor = function (id) {
    $('#' + id).xheditor({ tools: 'FontSize,Bold,Italic,Underline,Strikethrough,|,Align,List,|,Link,Img,Source' });
};

var rdTime = function () {
    return new Date().getTime();
};


var strToTime = function (s) {
    var d = new Date(Date.parse(s.replace(/-/g, "/")));
    return d;
};